﻿using Direct.IDAL.User.Jurisdiction;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DirectSell.DAL.User.Jurisdiction
{
    /// <summary>
    /// 变更密码数据访问层
    /// </summary>
    public class ModifyPasswordRepository:AbsRepository, IModifyPasswordRepository
    {

        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary>
        public ModifyPasswordRepository():base("UserInforMations")
        {

        }
        #endregion

        #region 判断一级密码--郭文昊--2018年10月31日14:22:08
        /// <summary>
        /// 判断一级密码
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public async Task<bool> CheckPassword(string usercode,string password)
        {
            var sql = new StringBuilder().Append(" SELECT COUNT(*)  FROM UserInforMations ")
                 .AppendFormat(" WHERE UserCode ='{0}'  AND UserPassWord='{1}'", usercode, password);
            return await base.QueryCount<long>(sql.ToString()) > 0;
        }
        #endregion

        #region 判断二级密码--郭文昊--2018年10月31日14:22:08
        /// <summary>
        /// 判断二级密码
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public async Task<bool> CheckSecondPassword(string usercode, string secondpassword)
        {
            var sql = new StringBuilder().Append(" SELECT COUNT(*)  FROM UserInforMations ")
                 .AppendFormat(" WHERE UserCode ='{0}'  AND UserSecondPassWord='{1}'", usercode, secondpassword);
            return await base.QueryCount<long>(sql.ToString()) > 0;
        }
        #endregion

        #region 修改一级密码--郭文昊--2018年10月31日14:28:23
        /// <summary>
        /// 修改一级密码
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool ModifyPassword(string password,string usercode)
        {
            string sql = string.Format("UPDATE UserInforMations SET UserPassWord='{0}' WHERE UserCode='{1}'", password, usercode);
            return base.Execute(sql);
        }
        #endregion

        #region 修改二级密码--郭文昊--2018年10月31日14:28:23
        /// <summary>
        /// 修改二级密码
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool ModifySecondPassword(string password, string usercode)
        {
            string sql = string.Format("UPDATE UserInforMations SET UserSecondPassWord='{0}' WHERE UserCode='{1}'", password, usercode);
            return base.Execute(sql);
        }
        #endregion

    }
}
